import * as React from "react";
import Box from "@mui/material/Box";
import Drawer from "@mui/material/Drawer";
import AppBar from "@mui/material/AppBar";
import Toolbar from "@mui/material/Toolbar";
import Typography from "@mui/material/Typography";
import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell";
import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import Paper from "@mui/material/Paper";
import SidebarList from "../components/sideBarList";
import Header from "../components/header";
import Footer from "../components/footer";
import DownloadListTable from "../components/downloadTable";

import "../assets/css/box.css";
import { useEffect, useState } from "react";
import http from "../utils/http/http";
import generateId from "../utils/http/generateId";

export default function DownloadList() {
  const [data, setData] = useState([]);

  useEffect(() => {
    // 发起POST请求;
    http
      .post("http://115.171.37.56:6800/jsonrpc", {
        jsonrpc: "2.0",
        method: "aria2.tellActive",
        id: generateId(),
        params: [
          [
            "gid",
            "totalLength",
            "completedLength",
            "uploadSpeed",
            "downloadSpeed",
            "connections",
            "numSeeders",
            "seeder",
            "status",
            "errorCode",
            "verifiedLength",
            "verifyIntegrityPending",
            "files",
            "bittorrent",
            "infoHash",
          ],
        ],
      })
      .then((response) => {
        // 处理响应数据
        let apiResult = response.result;
        setData(apiResult);
        //console.log(apiResult);
      })
      .catch((error) => {
        // 处理错误
        // 处理
        console.error(error);
      });
  }, []);
  return (
    <Box sx={{ display: "flex" }} className="boxRoot">
      <SidebarList />
      <Box component="main" sx={{ flexGrow: 1, p: 3 }}>
        <Header />
        <Toolbar />
        {/* Main content */}
        <DownloadListTable data={data} />
      </Box>
      <Toolbar />
      <Footer />
    </Box>
  );
}
